"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChargeDao = void 0;
const DbConfig_1 = require("../../src/config/DbConfig");
const DaoBase_1 = require("../../src/engine/dao/DaoBase");
const DateUtil_1 = require("../../src/engine/utils/DateUtil");
const MysqlManager_1 = require("../../src/engine/utils/MysqlManager");
class ChargeDao extends DaoBase_1.DaoBase {
    static insertOrder(order_id, userid, goodid, rmb, create_time, type, chargenum) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = 'INSERT INTO ' + this.Tb_Name + '(order_id,userid,goodid,rmb,status,create_time, type,chargenum) VALUES(?,?,?,?,?,?,?,?) ;';
            let sqlParams = [order_id, userid, goodid, rmb, 0, create_time, type, chargenum];
            let results = yield client.queryPromise(sql, sqlParams);
            if (results && results["affectedRows"] > 0) {
                return true;
            }
            else {
                return false;
            }
        });
    }
    static getOrder(order_id) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "select * from " + this.DB_NAME + "." + this.Tb_Name + " where `order_id`=?;";
            let sqlParams = [order_id];
            let results = yield client.queryPromise(sql, sqlParams);
            if (results && results.length > 0) {
                return results[0];
            }
        });
    }
    static finishOrder(order_id) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "update " + this.DB_NAME + "." + this.Tb_Name + " set `pay_time`=?, status=1  where `order_id`=?";
            let sqlParams = [DateUtil_1.default.formatDateStr(DateUtil_1.default.now()), order_id];
            let results = yield client.queryPromise(sql, sqlParams);
            if (results && results["affectedRows"] > 0) {
                return true;
            }
            else {
                return false;
            }
        });
    }
    static clear(delete_time) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "delete from t_charges where status=0 and create_time < ?";
            let sqlParams = [DateUtil_1.default.formatDateStr(delete_time)];
            yield client.queryPromise(sql, sqlParams);
        });
    }
    static game_date_charge_data(startTime, endTime) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = `select  t_charges.userid,rmb,chargenum,type,pay_time, nick_name, headimg from t_charges left join t_users on t_charges.userid=t_users.userid where pay_time >= ? and pay_time < ? and status = 1 `;
            let sqlParams = [startTime, endTime];
            let results = yield client.queryPromise(sql, sqlParams);
            return results;
        });
    }
    static game_week_charge_data(startTime, endTime) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = `select * from t_charges where pay_time >= ? and pay_time < ? and status = 1`;
            let sqlParams = [startTime, endTime];
            let results = yield client.queryPromise(sql, sqlParams);
            return results;
        });
    }
}
exports.ChargeDao = ChargeDao;
ChargeDao.DB_NAME = DbConfig_1.DbConfig.Db_Name.db_admin;
ChargeDao.Tb_Name = "t_charges";
